/**
 * @file       Frame_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "Frame.h"
#include "gtest/gtest.h"
#include "MockFrame.h"
#include "errorcode.h"
#include "Point.h"
#include "MockDisplay.h"
#include "Panel.h"
namespace NS_LCD_AFW
{
class CFrame_test: public ::testing::Test
{
public:
	virtual void SetUp()
	{
		OBJ_NEW(CMockDisplay,m_pDisplay);
		OBJ_NEW(CPanel,m_pActivePanel);
		m_pActivePanel->create("test",CRect(0,0,10,1));
	}
	virtual void TearDown()
	{
		OBJ_DELETE(m_pDisplay);
		OBJ_DESTORY(m_pActivePanel);
	}
protected:
	IDisplay *m_pDisplay;
	CPanel *m_pActivePanel;
};
TEST_F(CFrame_test,test_defualtConstruction)
{
	CFrame *pFrame = new CMockFrame();
	EXPECT_FALSE(pFrame->isFocusable());
	EXPECT_FALSE(pFrame->hasFocus());
	EXPECT_FALSE(pFrame->isHightlightable());
	EXPECT_FALSE(pFrame->isHightlightable());
	EXPECT_EQ(NULL, pFrame->getParent());
	EXPECT_EQ(CRect(0,0,0,0), pFrame->getRect());
	EXPECT_EQ(CPoint(0,0), pFrame->getPosition());
	EXPECT_EQ("", pFrame->getName());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_create)
{
	CRect normalRect(0, 0, 1, 1);
	CRect invalidRect(0, 0, 0, 0);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_FRAME_NAME_EMPTY, pFrame->create("",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_INVALID_RECT, pFrame->create("test",invalidRect,NULL,NULL));
	EXPECT_EQ(NULL, pFrame->getParent());
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,pFrame,NULL));
	EXPECT_EQ(NULL, pFrame->getParent());

	CFrame *pParentFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,pParentFrame,NULL));
	EXPECT_EQ(pParentFrame, pFrame->getParent());
	OBJ_DESTORY(pParentFrame);
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_show)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_SUCCESS, pFrame->show());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_getName)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ("test", pFrame->getName());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setRect)
{
	CRect normalRect(0, 0, 1, 1);
	CRect invalidRect(0, 0, 0, 0);

	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(normalRect, pFrame->getRect());

	EXPECT_EQ(ERR_NO_CHANGE, pFrame->setRect(normalRect));

	EXPECT_EQ(ERR_INVALID_RECT, pFrame->setRect(invalidRect));
	EXPECT_EQ(normalRect, pFrame->getRect());

	EXPECT_EQ(ERR_SUCCESS, pFrame->setRect(CRect(0,0,10,10)));
	EXPECT_EQ(CRect(0,0,10,10), pFrame->getRect());

	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setPosition)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(CPoint(0,0), pFrame->getPosition());
	EXPECT_EQ(ERR_NO_CHANGE, pFrame->setPosition(CPoint(0,0)));
	EXPECT_EQ(ERR_SUCCESS, pFrame->setPosition(CPoint(1,1)));
	EXPECT_EQ(CPoint(1,1), pFrame->getPosition());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_getPosition)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(CPoint(0,0), pFrame->getPosition());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_isFocusable)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->isFocusable());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_isHightlightable)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->isHightlightable());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_hasFocus)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->hasFocus());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setFocus)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->hasFocus());
	EXPECT_EQ(ERR_UN_FOCUS_ABLE,pFrame->setFocus(true));
	pFrame->setFocusable(true);
	EXPECT_EQ(ERR_SUCCESS,pFrame->setFocus(true));
	EXPECT_EQ(ERR_NO_CHANGE,pFrame->setFocus(true));
	EXPECT_EQ(ERR_SUCCESS,pFrame->setFocus(false));
	EXPECT_EQ(ERR_NO_CHANGE,pFrame->setFocus(false));
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_isHightlight)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->isHightlight());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setHightlight)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->isHightlight());
	EXPECT_EQ(ERR_UN_HIGHTLIGHT_ABLE,pFrame->setHightlight(true));
	EXPECT_EQ(ERR_UN_HIGHTLIGHT_ABLE,pFrame->setHightlight(false));
	pFrame->setHightlightable(true);
	EXPECT_TRUE(pFrame->isHightlightable());
	EXPECT_EQ(ERR_SUCCESS,pFrame->setHightlight(true));
	EXPECT_EQ(ERR_NO_CHANGE,pFrame->setHightlight(true));
	EXPECT_EQ(ERR_SUCCESS, pFrame->setHightlight(false));
	EXPECT_EQ(ERR_NO_CHANGE, pFrame->setHightlight(false));
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_invalidate)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_SUCCESS,pFrame->invalidate());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_invalidateRect)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_SUCCESS,pFrame->invalidateRect(normalRect));
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_postMessage)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_SUCCESS, pFrame->postEvent(0,0));
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onDraw)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_NULL_POINTER, pFrame->onDraw(NULL));
	EXPECT_EQ(ERR_SUCCESS,pFrame->onDraw(m_pDisplay));
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_getParent)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame =  new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(NULL,pFrame->getParent());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setFocusable)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame =  new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->isFocusable());
	pFrame->setFocusable(true);
	EXPECT_TRUE(pFrame->isFocusable());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setHightlightable)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_FALSE(pFrame->isHightlightable());
	pFrame->setHightlightable(true);
	EXPECT_TRUE(pFrame->isHightlightable());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_notify)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	//pFrame->notify();
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_preCreate)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->preCreate();
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onCreate)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_SUCCESS,pFrame->onCreate());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onSetFocus)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->onSetFocus();
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onLostFocus)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->onLostFocus();
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onHightlight)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->onHightlight();
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onUnHightlight)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->onUnHightlight();
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onSize)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->onSize(normalRect,normalRect);
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onClose)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->onClose();
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onMove)
{
	CRect normalRect(0, 0, 1, 1);
	CMockFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	pFrame->onMove(CPoint(0,0),CPoint(1,1));
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onLeftKeyPress)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pFrame->onLeftKeyPress());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onRightKeyPress)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pFrame->onRightKeyPress());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onUpKeyPress)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pFrame->onUpKeyPress());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onDownKeyPress)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pFrame->onDownKeyPress());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onEnterKeyPress)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pFrame->onEnterKeyPress());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_onEscKeyPress)
{
	CRect normalRect(0, 0, 1, 1);
	CFrame *pFrame = new CMockFrame();
	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pFrame->onEscKeyPress());
	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setParent)
{
//	CRect normalRect(0, 0, 1, 1);
//	CFrame *pFrame = new CMockFrame();
//	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
//	OBJ_DESTORY(pFrame);
}
TEST_F(CFrame_test,test_setName)
{
//	CRect normalRect(0, 0, 1, 1);
//	CFrame *pFrame = new CMockFrame();
//	EXPECT_EQ(ERR_SUCCESS, pFrame->create("test",normalRect,NULL,NULL));
//	OBJ_DESTORY(pFrame);
}

} /* namespace NS_LCD_AFW */
